(function($, window) {
	const ClipboardJS = require('clipboard');

	/**
	 * 获取剪切板数据
	 * @return {Promise}
	 */
	$.define('getClipboardData', function(options = {}) {
		return new Promise((resolve, reject) => {
			if (window.clipboardData && window.clipboardData.getData) {
				const data = window.clipboardData.getData('Text');
				resolve({data: data});
			} else {
				reject(new Error('getClipboardData 未实现'));
			}
		}, options);
	});

	/**
	 * 设置剪切板数据
	 * @param {{data:string,success?: Function, fail?: Function, complete?: Function}} options
	 * @return {Promise}
	 */
	$.define('setClipboardData', function(options) {
		return new Promise((resolve, reject) => {
			if (window.clipboardData && window.clipboardData.setData) {
				if (window.clipboardData.setData('Text', options.data)) {
					resolve({data: options.data});
				} else {
					reject(new Error('设置失败'));
				}
			} else {
				reject(new Error('setClipboardData 未实现'));
			}
		}, options);
	});

	/**
	 * 清空剪切板
	 * @return {boolean}
	 */
	$.define('clearClipboardData', function() {
		if (window.clipboardData && window.clipboardData.clearData)
			return window.clipboardData.clearData('Text');
		return false;
	});

})($);
